using System;
using System.ComponentModel.DataAnnotations;
namespace server.Models;

[Flags]
public enum Right
{
    None = 0,
    ViewBook = 1,
    BorrowBook = 2,
    AddBook = 4,
    EditBook = 8,
    DeleteBook = 16,
    ViewUser = 32,
    AddUser = 64,
    EditUser = 128,
    DeleteUser = 256,
    BookManager=AddBook|EditBook|DeleteBook,
    UserManager=ViewUser|AddUser|DeleteUser,
    SuperManager=BookManager|UserManager,
}


public class Role
{
    [Key]
    public int ID { get; set; }
    [Required]
    public string Name { get; set; } = null!;
    [Required]
    public Right Right { get; set; }
}

public static class BasicRole
{

    public static Role Visitor => new Role { Name = "Visitor", Right = Right.ViewBook };
    public static Role Reader => new Role { Name = "Reader", Right = Right.ViewBook | Right.BorrowBook };
    public static Role BookManager => new Role { Name = "BookManager", Right = Right.BookManager };
    public static Role UserManager => new Role { Name = "UserManager", Right = Right.UserManager };
    public static Role SuperManager => new Role { Name = "SuperManager", Right = Right.BookManager|Right.UserManager };
}